//
//  MQDetailVCOfFind.m
//  MinDyNews
//
//  Created by ZMQ on 16/7/21.
//  Copyright © 2016年 MQ. All rights reserved.
//

#import "MQDetailVCOfFind.h"
#import "MQDetailCellOfFind.h"
#import "MQSmallDetailFind.h"
#import "MQSamllModelOfFind.h"



@interface MQDetailVCOfFind ()<UITableViewDelegate, UITableViewDataSource>

//自定义的控件
@property (nonatomic, retain) UITableView *tableView;


@property(nonatomic, retain) NSMutableArray *arrOfModel;
@property(nonatomic, retain) WKWebView *webView;
@property(nonatomic, assign) NSInteger number;

@end

@implementation MQDetailVCOfFind

- (void)viewDidLoad {
     [super viewDidLoad];
    [self configtableView];
    [self handleData];
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
}

-(void)handleData{
    
    self.arrOfModel = [NSMutableArray array];
    NSString *str = [NSString string];
    
    str = @"http://baobab.wandoujia.com/api/v3/tag/videos?_s=c05e46762d8a22c7f70aa3a7c5889c59&f=iphone&net=wifi&num=20&start=0&strategy=date&tagId=658&u=4fe7fe9f7769435cedc2b627e7f169149d056136&v=2.3.1&vc=904";
   
    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NSArray *arr = [dic objectForKey:@"itemList"];
        
        for (NSDictionary *dic1 in arr) {
            
            MQSamllModelOfFind *model = [[MQSamllModelOfFind alloc]init];
            
            [model setValuesForKeysWithDictionary:dic1];
            
            [self.arrOfModel addObject:model];
        }
        
        
        [self.tableView reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    }




- (void)loadData {
    
    
        NSString *str   = [NSString stringWithFormat:@"http://baobab.wandoujia.com/api/v3/videos?start=%ld&num=20&categoryId=%@", (long)_number, self.idOfPage];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NSArray *arr = [dic objectForKey:@"itemList"];
        
        for (NSDictionary *dic1 in arr) {
            
            MQSamllModelOfFind *model = [[MQSamllModelOfFind alloc]init];
            
            [model setValuesForKeysWithDictionary:dic1];
            
            [self.arrOfModel addObject:model];
        }
        
        
        [self.tableView reloadData];
        
        
    } failure:nil];
    
    [self.tableView.mj_footer endRefreshing];
    

}



-(void)configtableView{
    
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view).with.offset(64);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        
    }];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[MQDetailCellOfFind class] forCellReuseIdentifier:@"DetailCell"];
}





-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 200;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    
    return self.arrOfModel.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MQDetailCellOfFind *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailCell"];
    
    cell.model = self.arrOfModel[indexPath.row];
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        MQSmallDetailFind *svc = [[MQSmallDetailFind alloc]init];
        
        svc.model = self.arrOfModel[indexPath.row];
        
        [self presentViewController:svc animated:YES completion:nil];
}

-(void)ClickFanHui{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}



@end
